<template>
	<view class="">
		<!-- 头部 -->
		<pagehead>修改支付密码</pagehead>
		<view class="form-warp">
			<view class="form-box">
				<view class="form-item">
					<view class="form-item-label">
						登录手机号
					</view>
					<view class="form-item-inner">{{ userInfo.sys_user_account | conceal(4) }}</view>
				</view>
				<view class="form-item">
					<view class="form-item-label">
						密码
					</view>
					<u--input class="form-item-inner" placeholder="请输入密码" type="password"
						customStyle="marginLeft:40rpx;marginRight:40rpx;" border="none" v-model="form.password">
					</u--input>
				</view>
				<view class="form-item">
					<view class="form-item-label">
						确认密码
					</view>
					<u--input class="form-item-inner" placeholder="请输入确认密码" type="password"
						customStyle="marginLeft:40rpx;marginRight:40rpx;" border="none" v-model="form.rePassword">
					</u--input>
				</view>
				<view class="form-item">
					<view class="form-item-label">
						图形验证码
					</view>
					<u--input class="form-item-inner" placeholder="请输入图形验证码" type="text"
						customStyle="marginLeft:40rpx;marginRight:40rpx;" border="none" v-model="form.tuCode">
					</u--input>
					<image class="tuCode" :src="img_io" mode="widthFix" @click="getTucode()"></image>
				</view>
				<view class="form-item">
					<view class="form-item-label">
						验证码
					</view>
					<u--input class="form-item-inner" placeholder="请输入验证码" type="text"
						customStyle="marginLeft:40rpx;marginRight:40rpx;" border="none" v-model="form.code">
					</u--input>
					<view class="form-item-code" @click="sendCode()"><text class="code">{{ remain }}</text></view>
				</view>
			</view>
			<view class="submit" @tap.stop="submit()">
				确定
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isSend: true,
			remain: '获取验证码',
			time: 60,
			form: {
				password:'',
				rePassword:'',
				tuCode: '',
				code: '',
			},
			img_io:'',
			addstatus: false,
			userInfo: uni.getStorageSync('usermsg') ? uni.getStorageSync('usermsg') : {}
		};
	},
	onLoad() {
		this.getTucode()
	},
	methods: {
		submit() {
			let that = this;
			if (!that.form.password) {
				return that.$tools.toast('请输入密码');
			}
			var reg1 = /^\d{6}$/;
      if(!reg1.test(that.form.password)){
        return that.$tools.toast('请输入6位数字密码');
      }
			if (!that.form.rePassword) {
				return that.$tools.toast('请输入确认密码');
			}
			if (that.form.password != that.form.rePassword) {
				return that.$tools.toast('两者密码不一致');
			}
			if (!that.form.tuCode) {
				return that.$tools.toast('请输入图形验证码');
			}
			if (!that.form.code) {
				return that.$tools.toast('请输入验证码');
			}
			let userBankQo = {
				"pay_password": that.$md5(that.form.password),
				"sms_code": that.form.code,
			}
			that.$Ajax('/api/user/setting/modifyPayPass', userBankQo, res => {
				if (res.success) {
					that.$tools.toastBack(res.msg, 1);
				}
			})
		},
		// 发送短信
		sendCode() {
			// if (this.userInfo.sys_user_account == '') {
			// 	return this.$tools.toast('请输入手机号');
			// }
			if (this.form.tuCode == '') {
				return this.$tools.toast('请输入图形验证码');
			}
			if (this.isSend == true) {
				uni.showLoading({
					title: '发送中',
					mask: true
				});
				var data = {
					// user_account: this.phone,
					bus_type: 'FrontModifyPayPass',
					img_id: this.img_id,
					img_code: this.form.tuCode,
				};
				console.log("data：", data);
				this.$Ajax('/api/common/smsCode/sendSmsCodeToken',
					data,
					res => {
						this.$tools.toast('短信发送成功')
						this.isSend = false;
						this.remain = this.time + 's';
						this.timer = setInterval(() => {
							this.time--;
							this.remain = this.time + 's';
							if (this.time == 0) {
								clearInterval(this.timer);
								this.remain = '重新获取';
								(this.isSend = true), (this.time = 60);
							}
						}, 1000);
					}
				)
				uni.hideLoading();
			}
		},
		// 获取图形验证码
		getTucode() {
			const data = {
				interface_type: 'createImgCode'
			}
			this.$Ajax('/api/common/imgCode/createImgCode', data, res => {
				// console.log('data',res)
				if (res.success) {
					this.img_id = res.data.img_id
					this.img_io = res.data.img_io
				}
			})
		},
	},
};
</script>

<style lang="scss" scoped>
@import '@/common/scss/operate';
</style>
